package com.intelligencesoft.pss.dao.binding;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.intelligencesoft.pss.dao.BaseDao;
import com.intelligencesoft.pss.entity.binding.UserBinding;
import com.intelligencesoft.pss.enums.BindingType;

@Repository
public class UserBindingDao extends BaseDao<UserBinding>{
	
	public UserBinding findUserBindsByUserIdAndType(String userId,BindingType bindingType){
		String hql = "FROM UserBinding ub WHERE ub.userInfo.id = :userId AND bindingList.bindingType = :bindingType";
		Query query = this.getSession().createQuery(hql);
		query.setString("userId", userId);
		query.setParameter("bindingType", bindingType);
		List<UserBinding> userBindings= (List<UserBinding>)query.list();
		if(userBindings.size() >0){
			return userBindings.get(0);
		}
		return null;
	}
	
	public List<UserBinding> findUserBindsByUserId(String userId){
		String hql = "FROM UserBinding ub WHERE ub.userInfo.id = :userId";
		Query query = this.getSession().createQuery(hql);
		query.setString("userId", userId);
		return (List<UserBinding>)query.list();
	}
}
